﻿//=======================================================================================
//一个form组件的构成定义
//【注】： 如果整体页面构成比较复杂，建议将各个复杂的子组件分别定义，
//         再以items的形式并入page对象的定义，以使代码更容易阅读
//=======================================================================================
var yongShuiInfo = {
    type  : "form", 
    name  : "yongShuiInfo",   
    title : "赠品领用管理",
    "enableCollapse" : false,
    "buttons"  : ["保存","关闭"],                

    "items"    : [
    	{   
            type:"calendar",    
            title:"领用日期",  
            allowBlank : false,    
            dataIndex:"dataset.deecontract.date" 
        },
        {   
            type:"numInput",    
            title:"领用金额",    
            allowBlank : false, 
            dataIndex:""  
        },
        {   
            type:"numInput",    
            title:"经手人",    
            allowBlank : false, 
            dataIndex:""  
        },
        {   
            type:"textArea",    
            title:"备注",    
            allowBlank : false, 
            dataIndex:""  
        }
    ],

    "layoutConfig" : {
        columns : 2
    },
    "layout" : [
        {                   
            items:[
            	{'name':'领用日期'},
                {'name':'领用金额'}
            ]
        },
        {
            items:[
               	{'name':'经手人'}
            ]
        },
        {
            items:[
                {'name':'备注', 'colspan':2}                
            ]
        }
    ]
};

var yongShuiInfoList={
    name      : "yongShuiInfoList",
    type      : "editGrid",
    title     : "用电管理",
    tbar      : ['新增', '-','删除', '-','全部删除','批量选择'],
    bbar      : false,
    allowBlank : false,
    
    bindRelation   : {                          //定义表格组件与数据的映射关系
        root  :"dataset.deecontract.deecontractList",           //获取列表数据的位置
        id    : "feiYianzhiid",            //列表记录的主键字段（唯一性判定标志）
        
        col   :[                                //表格的列模型定义(数据列+可交互的控制列)

            //-----------------------------------------------------------------
            //普通的数据列的定义
            //-----------------------------------------------------------------
            {   "header":"水表名称",     					"dataIndex":"dianbiaoname" 		},
            {	 	"header":"本月抄见数",        		"dataIndex":"benyuenum"	},
            {   "header":"上月抄见数",  					"dataIndex":"shangyuenum"},
            {   "header":"本月用水量",     	  		"dataIndex":"num"},
            {   "header":"备注",   								"dataIndex":"remark"}
        ],
        editor:[
            {},
            {"type":"textField",    "config":{"allowBlank":false}},
            {},
            {"type":"textField",    "config":{"allowBlank":false}},
            {}
        ]
        
    }
};


var page1 = new Sail.page({
    name     : "用水新增",                      //定义页面对象的唯一标识
    haveNavi : false,                           //未包含导航条

    frames   : {

        name     : "test0",                     //该frame对象的唯一标识
        getURL   : "data/yongDian.txt",   //标明如果有数据需要获取，获取的url
        postURL  : "yongDian.txt",                  //标明保存的服务路径
        bindDataFirst : true,
        
        
        items    : [yongShuiInfo],    //以JSON形式描述 frame 的组成(包含哪些items)

        //-------------------------------------------------------------------------------
        //【注】 添加 businessData 空结构
        //-------------------------------------------------------------------------------
        businessData : {
           "dataset":{
			        "deecontract":
			        	{	
			        		"bumen":"",
			        		"yongdianid":"",
				        	"data":"",
				        	"sbdata":"",
				        	"dianbiaoname":"",
				        	"benyuenum":"",
			        		"shangyuenum":"",
			        		"num":"",
			        		"beilv":"",
			        		"remark":""
				        }
				    }
        },
        afterUpdateBusiness : function(){
            this.updateBusinessData("dataset.deecontract","year",'2009');
        },
        //-------------------------------------------------------------------------------
        //【注】为当前 frame 的items 绑定事件
        //-------------------------------------------------------------------------------
        bindEvent2Items : function(){    
            
            //---------------------------------------------------------------------------
            //form的按钮事件
            //---------------------------------------------------------------------------
            $('yongShuiInfo').getButton('保存').on('click',function(){
                $('yongShuiInfo').ownerFrame.saveBusiness();
            });
            
            $('yongShuiInfo').getButton('关闭').on('click',function(){
                window.close();
            });
    		}
    }		
});

page1.run();